﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game.Foundation.ChineseChess
{
    public class Ma : ChessmanBase
    {
        public Ma(Chessboard board, Camp camp, string text) : base(board, camp, text) { }

        public override bool CanMoveTo(int xLocation, int yLocation)
        {
            int xoffset = xLocation - this.XLocation;
            int yoffset = yLocation - this.YLocation;
            if (Math.Abs(xoffset * yoffset) == 2)
            {
                int xbalk, ybalk;
                if (Math.Abs(xoffset) == 2)
                {
                    xbalk = (xLocation + this.XLocation) / 2;
                    ybalk = this.YLocation;
                }
                else
                {
                    xbalk = this.XLocation;
                    ybalk = (yLocation + this.YLocation) / 2;
                }

                return this._board.GetChessman(xbalk, ybalk) == null;
            }


            return false;
        }
    }
}
